﻿<window:myMangaWindow
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="http://schemas.microsoft.com/netfx/2007/xaml/presentation"
    xmlns:window="clr-namespace:myManga_App.Themes.Window"
    xmlns:ViewModels="clr-namespace:myManga_App.ViewModels"
    xmlns:MVVM="clr-namespace:myManga_App.Objects.MVVM"
    xmlns:AssemblyInformation="clr-namespace:myManga_App.Objects.About"
    xmlns:App="clr-namespace:myManga_App"
    xmlns:Button="clr-namespace:myManga_App.Resources.Theme.Buttons"
    xmlns:Converters="clr-namespace:myManga_App.Converters" 
    x:Class="myManga_App.MainWindow"
    Title="{DynamicResource AppTitle}"
    WindowState="{Binding UserConfig.WindowState, Mode=TwoWay, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged}"
    Width="{Binding UserConfig.WindowSizeWidth, FallbackValue=640, Mode=TwoWay, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged}"
    Height="{Binding UserConfig.WindowSizeHeight, FallbackValue=480, Mode=TwoWay, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged}"
    x:Name="myMangaMainWindow"
    MinHeight="480"
    MinWidth="640"
    Icon="/myManga;component/Resources/Icon.ico"
    SnapsToDevicePixels="True" 
    Style="{DynamicResource myMangaWindow}">
    <window:myMangaWindow.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/myManga;component/Themes/Window/myMangaWindow.xaml"/>
                <ResourceDictionary Source="/myManga;component/Themes/CoreResourceDictionary.xaml"/>
                <ResourceDictionary Source="/myManga;component/Resources/Localization/Dictionary_en-US.xaml"/>
                <ResourceDictionary Source="/myManga;component/Resources/ViewModel-View-Link.xaml"/>

                <ResourceDictionary Source="/myManga;component/Themes/ProgressBar/Spinner.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <Converters:EnumToBooleanConverter x:Key="EnumToBooleanConverter"/>
            <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        </ResourceDictionary>
    </window:myMangaWindow.Resources>
    <window:myMangaWindow.DataContext>
        <ViewModels:MainViewModel/>
    </window:myMangaWindow.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <StackPanel
			Grid.Row="0"
			Orientation="Horizontal"
			TextElement.FontSize="20"
			TextElement.FontFamily="{DynamicResource OpenIconic}">
            <Button:MetroButton
                Content="{DynamicResource HomeTabHeaderContent}"
				ToolTip="{DynamicResource HomeTabHeaderName}"
				Command="{Binding HomeCommand}"
				MinWidth="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
                Margin="3px 0px"/>
            <Button:MetroButton
				Content="{DynamicResource SearchTabHeaderContent}"
				ToolTip="{DynamicResource SearchTabHeaderName}"
				Command="{Binding SearchCommand}"
				MinWidth="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
                Margin="3px 0px"/>
            <Button:MetroButton
				Content="{DynamicResource ReaderTabHeaderContent}"
				ToolTip="{DynamicResource ReaderTabHeaderName}"
				Command="{Binding ReadCommand}"
				MinWidth="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"
                Margin="3px 0px"/>
        </StackPanel>
        <StackPanel
			Grid.Column="1"
			Orientation="Horizontal">
            <ProgressBar
				VerticalAlignment="Center"
				Height="24"
				Width="{Binding Height, Mode=OneWay, RelativeSource={RelativeSource Self}}" 
				Style="{DynamicResource Spinner}" 
				Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}"
                Foreground="{DynamicResource text-dark}"
				IsHitTestVisible="False"/>
            <StackPanel 
                Orientation="Horizontal" 
                TextElement.FontFamily="{DynamicResource OpenIconic}"
                TextElement.FontSize="20"
                VerticalAlignment="Center"
                Visibility="{Binding ContentViewModel.SupportsViewTypeChange, Converter={StaticResource BooleanToVisibilityConverter}, Mode=OneWay}">
                <Button:MetroRadioButton 
                    Content="{DynamicResource oi-list}" 
                    IsChecked="{Binding ContentViewModel.ViewType, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static MVVM:ViewModelViewType.Normal}, Mode=TwoWay}"/>
                <Button:MetroRadioButton 
                    Content="{DynamicResource oi-grid-four-up}"
                    IsChecked="{Binding ContentViewModel.ViewType, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter={x:Static MVVM:ViewModelViewType.Grid}, Mode=TwoWay}"/>
            </StackPanel>
            <Button:MetroButton
				TextElement.FontSize="20"
				TextElement.FontFamily="{DynamicResource OpenIconic}"
				Content="{DynamicResource oi-wrench}"
				ContentStringFormat="Settings {0}"
				ToolTip="Settings"
				Command="{Binding SettingsCommand}"
				MinWidth="{Binding ActualHeight, Mode=OneWay, RelativeSource={RelativeSource Self}}"/>
        </StackPanel>
        <ContentPresenter
			Grid.Row="1"
			Grid.ColumnSpan="2"
			Content="{Binding ContentViewModel}" 
			Margin="5,0,5,5"/>
        <Grid
			x:Name="Watermark"
			Panel.ZIndex="99"
			Grid.RowSpan="2"
            TextElement.Foreground="{DynamicResource window-foreground}"
			IsHitTestVisible="False"
			VerticalAlignment="Center"
			HorizontalAlignment="Center">
            <Grid.LayoutTransform>
                <ScaleTransform x:Name="WatermarkScale" ScaleX="1" ScaleY="1"/>
            </Grid.LayoutTransform>
            <Grid.Triggers>
                <EventTrigger RoutedEvent="FrameworkElement.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation 
								Storyboard.TargetName="Watermark"
								Storyboard.TargetProperty="Opacity"
								BeginTime="0:0:2"
								Duration="0:0:4"
								From="1" To="0"/>
                            <DoubleAnimation 
								Storyboard.TargetName="WatermarkScale"
								Storyboard.TargetProperty="ScaleX"
								BeginTime="0:0:2"
								Duration="0:0:4.5"
								From="1" To="0"/>
                            <DoubleAnimation 
								Storyboard.TargetName="WatermarkScale"
								Storyboard.TargetProperty="ScaleY"
								BeginTime="0:0:2"
								Duration="0:0:4.5"
								From="1" To="0"/>
                            <ObjectAnimationUsingKeyFrames 
								Storyboard.TargetName="Watermark"
								Storyboard.TargetProperty="Visibility">
                                <DiscreteObjectKeyFrame
									KeyTime="0:0:6.5"
									Value="{x:Static Visibility.Hidden}"/>
                            </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Grid.Triggers>
            <Border
                BorderThickness="3"
                BorderBrush="{DynamicResource window-theme-primary}"
                Background="{DynamicResource window-background}"/>
            <StackPanel Orientation="Vertical" Margin="7">
                <Grid Margin="5,0,0,-20" TextElement.FontSize="16" TextElement.FontWeight="Bold">
                    <TextBlock Text="{DynamicResource ProjectURL}" HorizontalAlignment="Left" />
                    <TextBlock Text="{Binding Version, Source={x:Static AssemblyInformation:AssemblyInformation.Default}, StringFormat=v{0}}" HorizontalAlignment="Right" />
                </Grid>
                <TextBlock Text="{DynamicResource AppTitle}" FontSize="50" Margin="0,0,0,0"/>
            </StackPanel>
        </Grid>
    </Grid>
</window:myMangaWindow>
